<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link type="text/css" href="/css/start/jquery-ui-1.8.21.custom.css" rel="Stylesheet" />	
<script type="text/javascript" src="/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/js/jquery-ui-1.8.21.custom.min.js"></script>
<style type="text/css">
.hasTooltip {
    position:relative;
}
.hasTooltip span {
    display:none;
}

.hasTooltip:hover span {
    display:block;
    background-color:#888;
    border-radius:1px;
    color:white;
    box-shadow:1px 1px 2px gray;
    position:absolute;
    padding:5px;
    top:0px;
    left:-250px;   
    width:250px; /* I don't want the width to be too large... */
	/*white-space: nowrap; */
}	
</style>
</head>

<body style="font-family:Arial, Helvetica, sans-serif">
<script>
	$(function() {
		$( "#date_begin" ).datepicker({ dateFormat: "yy-mm-dd",firstDay: 1 ,beforeShowDay: function(date){ return [date.getDay() == 1,""]}});
		$( "#date_end" ).datepicker({ dateFormat: "yy-mm-dd",firstDay: 1 });
	});
	</script>
<?php
$caOpen = new Model_DbTable_Cashaccountopening();
$list = $caOpen->listAllShopcode();
 
?>
Color Code : <span style="background-color:#FF8080;width:150px;">&nbsp;&nbsp;&nbsp;&nbsp;</span> Error Occur | <span style="background-color:#DEB363;width:150px;">&nbsp;&nbsp;&nbsp;&nbsp;</span> 
Need Your Attention  | <span style="background-color:#9CFECD;width:150px;">&nbsp;&nbsp;&nbsp;&nbsp;</span> Everything Ok | APOS Sales File Only Available After 04/29/2013,Please Only Select <em><strong>ONE WEEK   </strong></em>Check ALL <a href="/caaudit/short-daily-report-all" target="_blank">CLICK HERE</a>
<form action="" method="post">
  <p>Shopcode: <select name="shopcode"  id="shopcode">
    
    <?php foreach($list as $key => $v){ ?> 
    <option value="<?php echo $v['shop_code_ca']?>" 
    <?php 
	if($v['shop_code_ca'] == $this->shopCode){echo 'selected="selected"';}
	
	?>
    ><?php echo $v['shop_code_ca']?></option>
 <?php  } ?> 
  
</select>
     
  Date Begin [yyyy-mm-dd]:
    <input name="date_begin" id="date_begin" type="text" />  Date End:<input name="date_end" id="date_end" type="text" /> |  <input type="submit" name="button" id="button" value="Submit" />
  </p>
</form>
* Unmatch Invoice: Apos Invoice, The Type is EFTPOS, but we can not find Any Matching Amount of Commbiz entry within 2 mins. It may indicate Staff Type Cash Sales as EFTPOS  <br />

* Unmatch Receipt: We found a Commbiz Receipt that did NOT belong to any APOS EFTPOS Invoice within 2 mins.<br />

* If you found both Unmatch Invoice and Unmatch receipt with same amount, only the time gap is larger than 2mins. It is possible Staff create invoice too early.<br />
<br />

<table width="1950" border="1" cellspacing="0" cellpadding="5" >
  <tr>
  	<td align="center">Date</td>
    <td align="center">Time<br />
Staff</td>
    <td align="center">Yesterday <br />
    Closing</td>
    <td align="center">Today <br />
    Opening</td>
    <td align="center">CashOut</td>
    <td align="center">BankIn</td>
    <td align="center" bgcolor="#666666" style="width:1px">&nbsp;</td>
    <td align="center"><span style="font-size:12px">Cash InTill</span><br />
    <span style="font-size:8px">(After Bankin/Cashout)</span></td>
    <td colspan="2" align="center" style="width:150px;">Cash Sales</td>
    <td colspan="2" align="center" style="width:250px;">EFTPOS Sales<br />
      <span style="font-size:8px">(Qty M/Copy)</span></td>
    <td align="center">Total Sales<br />
      <span style="font-size:8px">(APOS Filled In)</span></td>
    <td align="center">APOS<br />
<span style="font-size:8px">(Real)</span></td>
    <td align="center"><span style="font-size:12px">Cash InTill</span><br />
    <span style="font-size:8px">(Before Expense)</span></td>    
    <td align="center">Expense</td>
    <td align="center">Today<br />
      Closing</td>

    <td align="center">Umatch<br />
    Invoice</td>
    <td align="center">Cash Inv</td>
    <td align="center">Umatch<br />
      Receipt</td>
          <td align="center">Remark</td>
    <td align="center">View File</td>
  </tr>
  <?php 
  if($_POST || $_GET){
  foreach($this->arraudit as $key => $v)
  {
  ?>
  <tr>
    <td rowspan="2">
    <?php 
	if($v[1]){
	echo $v[1][0]["date_record_open"];
	}
	elseif($v[2]){
	echo $v[2][0]["date_record_close"];
	}
	?>
    </td>
    <td rowspan="2" style="font-size:9px; font-stretch:narrower">
	<?php 
	if($v[1]){
	echo $v[1][0]["time_record_open"];
	echo " ".$v[1][0]["staff_name_prepare_open"];
	}
	 ?>
    <br /> 
	<?php 
	if($v[2]){
	echo $v[2][0]["time_record_close"];
	echo " ".$v[2][0]["staff_name_prepare_close"];
	} ?>
    </td>
    <td rowspan="2"
    <?php if(trim($v[3][0]["date_record_close"])!=trim($v[4])){ ?> 
    style="background-color:#FF8080;" 	
	<?php }?>
    >
    <?php 
	if($v[3]){
	echo $v[3][0]["close_balance_cash_close"]; 
	}?>
    <br /> 
    <?php
	//if(true){
    if(trim($v[3][0]["date_record_close"])!=trim($v[4])){
	echo "<span style=\"font-size:11px\">{$v[3][0]["date_record_close"]}</span>";	
		}
	?>
    </td>
    <td rowspan="2"
    <?php
    $openCash = 0 ;
	if($v[1]){
	$openCash = $v[1][0]["amount_note_100_open"];
	$openCash += $v[1][0]["amount_note_50_open"];
	$openCash += $v[1][0]["amount_note_20_open"];
	$openCash += $v[1][0]["amount_note_10_open"];
	$openCash += $v[1][0]["amount_note_5_open"];
	$openCash += $v[1][0]["amount_coin_2_open"];
	$openCash += $v[1][0]["amount_coin_1_open"];
	$openCash += $v[1][0]["amount_coin_05_open"];
	$openCash += $v[1][0]["amount_coin_02_open"];
	$openCash += $v[1][0]["amount_coin_01_open"];
	$openCash += $v[1][0]["amount_coin_005_open"];
	}
	if($openCash ==0 || abs($openCash - $v[3][0]["close_balance_cash_close"]) >0.04 ){
	?> 
    style="background-color:#FF8080;" 
    <?php }?>	
    
    >
    <?php
	echo $openCash;
	?>
    </td>
    <td rowspan="2"
    
    <?php
    if($v[1]){
	if($v[1][0]["amount_cash_out_open"] <10 &&  $v[1][0]["amount_bank_in_open"] <10){
	?> 
    style="background-color:#DEB363;"
    <?php }}?>
    >
	<?php
	if($v[1]){
	 echo $v[1][0]["amount_cash_out_open"]; 
	 }?>
    </td>
    <td rowspan="2"
 
        <?php
    if($v[1]){
	if($v[1][0]["amount_cash_out_open"] <10 &&  $v[1][0]["amount_bank_in_open"] <10){
	?> 
    style="background-color:#DEB363;"   
    <?php }}?>
    >
    <?php
	if($v[1]){
	 echo $v[1][0]["amount_bank_in_open"]; 
	}?>
    </td>
    <td rowspan="2" bgcolor="#666666">&nbsp;</td>
    <td rowspan="2"

     
	 <?php
	$openBalClose = 0;
	
	if($v[2]){
	$openBalClose = $v[2][0]["open_balance_close"];
	}
	if($openBalClose ==0){
	echo ' style="background-color:#FF8080;"';	
	}
	if($openBalClose >0 && $openBalClose < 300){
	?> 
        style="background-color:#DEB363;" 
    <?php } ?> 
    >
    <?php
	if($v[2]){
	 echo $v[2][0]["open_balance_close"];
	}?>
    </td>    
    <td
    <?php
	if($v[2]){
	 if($v[2][0]["total_cash_sales_close"]<100){
		 //echo ' style="background-color:#DEB363;"';
		 }
	}?>
     style=" font-size:12px; border-bottom-width:0px;"
     >IPT: $ <?php
	if($v[2]){
	 echo $v[2][0]["total_cash_sales_close"];
	}?></td>
    <td align="center"
    <?php
	if($v[2]){
	 if($v[2][0]["total_cash_sales_close"]<100){
		 //echo ' style="background-color:#DEB363;"';
		 }
	}?>
    style=" font-size:12px;border-bottom-width:0px;"
    >DIF:</td>
    <td 
     <?php
	if($v[2]){
	 if($v[2][0]["total_electronic_cash_close"]<100){
		// echo ' style="background-color:#DEB363;"';
		 }
	}?>
    style=" font-size:12px;border-bottom-width:0px;"
    >IPT : 
      <?php
	if($v[2]){
	 echo $v[2][0]["total_electronic_cash_close"]; 
	}?>
      [<span style="font-size:11px;">
      <?php
	if($v[2]){
	 echo $v[2][0]["qty_merchant_copy_close"]; 
	}?>
      </span>]</td>
    <td valign="top" 
     <?php
	if($v[2]){
	 if($v[2][0]["total_electronic_cash_close"]<100){
		// echo ' style="background-color:#DEB363;"';
		 }
	}?>
    style=" font-size:12px;border-bottom-width:0px;"
    ><table width="100%" border="0" cellspacing="0" cellpadding="0" style="font-size:11px;">
      <tr>
        <td>IPT</td>
        <td align="center">EF $<?php
	if($v[2]){
	 echo $v[2][0]["drcr_electronic_cash_close"]; 
	}?></td>
        <td align="center">AE $<?php
	if($v[2]){
	 echo $v[2][0]["amex_electronic_cash_close"]; 
	}?></td>
      </tr>
      <tr>
        <td>SY</td>
        <td align="center">EF $<?php
	if($v[2]){
	 echo $v[2][0]["apos_sys_sales_eft"]; 
	}?></td>
        <td align="center">AE $<?php
	if($v[2]){
	 echo $v[2][0]["apos_sys_sales_ae"]; 
	}?></td>
      </tr>
    </table></td>
    <td rowspan="2" 
    
    ><?php 
	if($v[2]){
	echo $v[2][0]["total_net_sales_close"]; 
	
	if($v[2][0]["total_net_sales_close"] < $v[2][0]["total_electronic_cash_close"] ){
		
	echo '<img src="/im/flag.jpg" title="Total Sales Less Than EFTPOS" />';
	}
	}
	?>
    
    
    </td>
    <td rowspan="2"
    <?php
    if($v[2]){
		if(abs($v[2][0]["total_net_sales_close"] - $v[2][0]["apos_sys_sales_total"]) >0.04){
			echo  'style="background-color:#FF8080;"';
			}
		}
	?>
     >
     <?php echo $v[2][0]["apos_sys_sales_total"];?>
    </td>
    <td rowspan="2" >
    <?php
	if($v[2]){
	 echo $v[2][0]["sub_expense_total"] + $v[2][0]["close_balance_cash_close"] ; 
	 } ?>
    </td>
    <td rowspan="2"
    <?php
	if($v[2]){
	 if($v[2][0]["sub_expense_total"] >0){ echo ' style="background-color:#DEB363;"'; }
	 } ?>
    
    >(<?php
	if($v[2]){
	 echo $v[2][0]["sub_expense_total"]; 
	 } ?>)</td>
    <td rowspan="2"><?php
	if($v[2]){
	 echo $v[2][0]["close_balance_cash_close"];
	}?></td>

    <td rowspan="2" style="font-size:11px;"><?php
	 if($v[2]){ 
	 //echo $v[2][0]['cb_um_inv']; 
	 if($v[2][0]['cb_um_inv']!=""){
		 $arrInv =array_chunk(unserialize(base64_decode($v[2][0]['cb_um_inv'])),3);
		
		 foreach($arrInv as $k => $vInv){
			 echo $vInv[0].":(".$vInv[1]." , $".$vInv[2].")<br />";
			 }
		 }
	}
	?></td>
    <td rowspan="2" style="font-size:11px;"><?php
	 if($v[2]){ 
	 echo $v[2][0]['cb_um_cash_inv']; 
	
	}
	?></td>
    <td rowspan="2" style="font-size:11px;"><?php
	 if($v[2]){ 
	 //echo $v[2][0]['cb_um_eft']; 
	 if($v[2][0]['cb_um_eft']!=""){
		 $arrInv =array_chunk(unserialize(base64_decode($v[2][0]['cb_um_eft'])),2);
		
		 foreach($arrInv as $k => $vInv){
			 echo $vInv[0].":($".$vInv[1].")<br />";
			 }
		 }
	}
	?></td>  
  	<td rowspan="2" 
    <?php
    $styleStr = ' style="font-size:11px;background-color:#9CFECD;"';
	if($v[1]){
		if(trim($v[1][0]["remark_open_cash_not_match"])!="" && 
		trim($v[1][0]["remark_open_cash_not_match"])!="1) Did you count the cash for TWO TIMES and they are the same amount? Answer:
2) Did you also do the closing Yesterday? Answer:"
		){
			$styleStr = ' style="font-size:11px;background-color:#DEB363;"';	
		}
	}
	if($v[2]){
		if(trim($v[2][0]["remark_close"])!=""){
			$styleStr = ' style="font-size:11px;background-color:#DEB363;"';	
		}
	}
	echo $styleStr;	
	?>
     > O:
     <?php
     	if($v[1]){
		if(trim($v[1][0]["remark_open_cash_not_match"])!=""  && 
		trim($v[1][0]["remark_open_cash_not_match"])!="1) Did you count the cash for TWO TIMES and they are the same amount? Answer:
2) Did you also do the closing Yesterday? Answer:"){	 
	 ?>
     <a href="#" class="hasTooltip">Remark<span><?=trim($v[1][0]["remark_open_cash_not_match"])?></span></a>
     <?php
	 		}
	}
	  ?>
     <br />
C:
<?php
	if($v[2]){
		if(trim($v[2][0]["remark_close"])!=""){
?>
<a href="#" class="hasTooltip">Remark<span><?=trim($v[2][0]["remark_close"])?></span></a>
<?php }} ?>


</td>
    <td rowspan="2" style="font-size:11px;">&nbsp;<?php
	if($v[1]){
    $fileNameOpen =$this->shopCode."-opening-".$v[1][0]["date_record_open"].".html";
	$fileNameClose =$this->shopCode."-closing-".$v[1][0]["date_record_open"].".html";
	$fileNameSummary =$this->shopCode."-".$v[1][0]["date_record_open"]."-sum.html";
	
	?>
      <a href="/ca/<?php echo $this->shopCode."/".$fileNameOpen?>" target="_blank">O</a> |
      <a href="/ca/<?php echo $this->shopCode."/".$fileNameClose?>" target="_blank">C</a> |
    <a href="/ca/<?php echo $this->shopCode."/".$fileNameSummary?>" target="_blank">S</a></td>    
      
  <?php
	}
  ?>
  </tr>
  <tr>
    <td
    <?php
	if($v[2]){
	 if($v[2][0]["total_cash_sales_close"]<100){
		 //echo ' style="background-color:#DEB363;"';
		 }
	}?>
   style=" font-size:12px; border-top-width:0px;"
    >SYS: $ <?php
	if($v[2]){
	 echo $v[2][0]["apos_sys_sales_cash"];
	}?></td>
    <td align="center"
    <?php
	if($v[2]){
	 if(abs(round($v[2][0]["total_cash_sales_close"] - $v[2][0]["apos_sys_sales_cash"],2)) <0.04 ){
		echo 'style=" font-size:12px; border-top-width:0px;background-color:#9CFECD;"'; 
		 //echo ' style="background-color:#DEB363;"';
		 }
	 else{
		if(abs(round($v[2][0]["total_cash_sales_close"] - $v[2][0]["apos_sys_sales_cash"] + $v[2][0]["total_electronic_cash_close"] - $v[2][0]["apos_sys_sales_eft"] - $v[2][0]["apos_sys_sales_ae"],2)) <0.04 ){
			 echo 'style=" font-size:12px; border-top-width:0px;background-color:#DEB363"'; 
			}
		else{
			 echo 'style=" font-size:12px; border-top-width:0px;background-color:#FF8080;"'; 
		}
}
	}?>
    
    >$
<?php 
    if($v[2]){
	 echo round($v[2][0]["total_cash_sales_close"] - $v[2][0]["apos_sys_sales_cash"],2) ;
	}?></td>
    <td 
     <?php
	if($v[2]){
	 if($v[2][0]["total_electronic_cash_close"]<100){
		// echo ' style="background-color:#DEB363;"';
		 }
	}?>
    style=" font-size:12px; border-top-width:0px;"
    >SYS:
      <?php
	if($v[2]){
	 echo $v[2][0]["apos_sys_sales_eft"] + $v[2][0]["apos_sys_sales_ae"]; 
	}?>
      [
      <?php
	if($v[2]){
	 echo $v[2][0]["apos_sys_qty_eft"] + $v[2][0]["apos_sys_qty_ae"]; 
	}?>
    ]</td>
    <td valign="top" 
     <?php
	if($v[2]){
		$amtDiff = round($v[2][0]["total_electronic_cash_close"] - $v[2][0]["apos_sys_sales_eft"] - $v[2][0]["apos_sys_sales_ae"],2);
		$qtyDiff = $v[2][0]["qty_merchant_copy_close"] - $v[2][0]["apos_sys_qty_eft"] - $v[2][0]["apos_sys_qty_ae"]; 
		
	 if(round($v[2][0]["total_electronic_cash_close"] - $v[2][0]["apos_sys_sales_eft"] - $v[2][0]["apos_sys_sales_ae"],2) < 0.04 && ($v[2][0]["qty_merchant_copy_close"] - $v[2][0]["apos_sys_qty_eft"] - $v[2][0]["apos_sys_qty_ae"]) ==0){
		echo ' style=" font-size:12px; border-top-width:0px;background-color:#9CFECD;"';
		 }
	else{
		if(
		(abs(round($v[2][0]["total_cash_sales_close"] - $v[2][0]["apos_sys_sales_cash"] + $v[2][0]["total_electronic_cash_close"] - $v[2][0]["apos_sys_sales_eft"] - $v[2][0]["apos_sys_sales_ae"],2)) <0.04 )
        &&
		(($amtDiff >0 &&  $qtyDiff >0) ||($amtDiff <0 &&  $qtyDiff <0) )
         ){
			//yellow
			 echo 'style=" font-size:12px; border-top-width:0px;background-color:#DEB363"'; 
			 }
		else{
			//red
			 echo 'style=" font-size:12px; border-top-width:0px;background-color:#FF8080;"'; 
			}	 		
		}	 
	}?>
    >DIF:
      <?php
	if($v[2]){
	 echo round($v[2][0]["total_electronic_cash_close"] - $v[2][0]["apos_sys_sales_eft"] - $v[2][0]["apos_sys_sales_ae"],2); 
	}?>
      [
      <?php
	if($v[2]){
	 echo $v[2][0]["qty_merchant_copy_close"] - $v[2][0]["apos_sys_qty_eft"] - $v[2][0]["apos_sys_qty_ae"]; 
	}?>
]</td>
  </tr>
 <?php
  
  
  }}
 ?> 
  <tr>
  	<td align="center">Date</td>
    <td align="center">Time</td>
    <td align="center">Yesterday <br />
    Closing</td>
    <td align="center">Today <br />
    Opening</td>
    <td align="center">CashOut</td>
    <td align="center">BankIn</td>
    <td align="center" bgcolor="#666666" style="width:1px">&nbsp;</td>
    <td align="center"><span style="font-size:12px">Cash InTill</span><br />
    <span style="font-size:8px">(After Bankin/Cashout)</span></td>
    <td colspan="2" align="center">Cash Sales</td>
    <td colspan="2" align="center">EFPOS Sales</td>
    <td align="center">Total Sales</td>
    <td align="center">APOS</td>
    <td align="center"><span style="font-size:12px">Cash InTill</span><br />
    <span style="font-size:8px">(Before Expense)</span></td>    
    <td align="center">Expense</td>
    <td align="center">Today<br />
Closing</td>

    <td colspan="2" align="center">Umatch<br />
Invoice</td>
    <td align="center">Umatch<br />
    Receipt</td>
    <td align="center">Remark</td>
    <td align="center">View File</td>
  </tr>
</table>
</body>
</html>